/**
 * Created by Administrator on 2016/9/3.
 */
"use strict";
swan_pc
    .controller("SessionDetailController",function($scope,$state,sessionManage,CommentManage,BigEventById){
        $scope.sessionId=$scope.$parent.sessionId;
        $scope.envolopeUrl=$scope.$parent.envolopeUrl;
        $scope.getSessionDetail=function(){
            sessionManage.get({id:$scope.sessionId},function(result){
                $scope.currentSession=result;
                BigEventById.get({id:$scope.currentSession.eventId},function(result){
                    $scope.currentBigEvent=result;
                });
                //console.log($scope.currentSession);
            })
        };
        $scope.getSessionDetail();
        /*
         *comment评论模块实现
         */
        $scope.newComment={
            activityId:0,
            activityType:"SESSION",
            content:null
        };
        $scope.allComments=[];
        $scope.initCommentDisplay=function() {
            $scope.commentsForCurrentEvent=[];
            CommentManage.query(function (result) {
                $scope.allComments = result;
                angular.forEach($scope.allComments, function (data, index, array) {
                    if (data.activityType == "SESSION" && data.activityId == $scope.sessionId) {
                        $scope.commentsForCurrentEvent.push(data);
                    }
                })
            },function(result){
            })
        };
        $scope.initCommentDisplay();
        $scope.submitComment=function(){
            $scope.newComment.activityId=$scope.sessionId;
            CommentManage.save($scope.newComment,function(result){
                $scope.initCommentDisplay();
                swal("提交评论成功","","success");
            },function(result){
                //console.log(result);
                swal("提交评论失败","","error");
            })
        }
        //activity 展示内容变换
        $scope.activeNumber=1;
        $scope.changeActivityShow=function(option){
            $scope.activeNumber=option;
        };
        //返回活动详情列表
        $scope.BackToActivityDetail=function(){
            $state.go("activitydetail");
        };
        //邀请函展示实现
        $scope.stationeryUrlList={
            "信纸1":"http://www.diamondtiming.com:8080/uploads/20160809131748_xin0.jpg",
            "信纸2":"http://www.diamondtiming.com:8080/uploads/20160809131803_xin1.jpg",
            "信纸3":"http://www.diamondtiming.com:8080/uploads/20160809131809_xin2.jpg",
            "信纸4":"http://www.diamondtiming.com:8080/uploads/20160809131815_xin3.jpg",
            "信纸5":"http://www.diamondtiming.com:8080/uploads/20160809131823_xin4.jpg"
        };
        if($scope.envolopeUrl!=null &&$scope.envolopeUrl!=undefined) {
            if ($scope.envolopeUrl.length > 5) {
                $scope.invationStyle = {
                    "position": 'center',
                    "background-image": 'url(http://www.diamondtiming.com:8080' + $scope.envolopeUrl + ')',
                    "background-size": 'cover',
                    "width": '100%',
                    "padding": "20% 0"
                }
                console.log($scope.invationStyle['background-image']);
            } else {
                for (var key in $scope.stationeryUrlList) {
                    if ($scope.envolopeUrl == key) {
                        var imageUrl = $scope.stationeryUrlList[key];
                        var imageUrl = imageUrl.split(".");
                        var imageUrlLength = imageUrl[2].length;
                        var imageFlag = imageUrl[2][imageUrlLength - 1];
                        if (imageFlag == 0) {
                            $scope.invationStyle = {
                                "position": 'center',
                                "background-image": 'url(' + $scope.stationeryUrlList[key] + ')',
                                "background-size": 'cover',
                                "width": '100%',
                                "padding": "20% 0"
                            }
                        } else if (imageFlag == 1) {
                            $scope.invationStyle = {
                                "position": 'center',
                                "background-image": 'url(' + $scope.stationeryUrlList[key] + ')',
                                "background-size": 'cover',
                                "width": '100%',
                                "padding": "20% 0",
                                "color": "white",
                                "text-shadow": "5px 5px 5px black"
                            }
                        } else if (imageFlag == 2) {
                            $scope.invationStyle = {
                                "position": 'center',
                                "background-image": 'url(' + $scope.stationeryUrlList[key] + ')',
                                "background-size": 'cover',
                                "width": '100%',
                                "padding": "30% 0",
                                "color": "white",
                            }
                        } else if (imageFlag == 3) {
                            $scope.invationStyle = {
                                "position": 'center',
                                "background-image": 'url(' + $scope.stationeryUrlList[key] + ')',
                                "background-size": 'cover',
                                "width": '100%',
                                "padding": "20% 0",
                                "color": "white"
                            }
                        } else {
                            $scope.invationStyle = {
                                "position": 'center',
                                "background-image": 'url(' + $scope.stationeryUrlList[key] + ')',
                                "background-size": 'cover',
                                "width": '100%',
                                "padding": "20% 0",
                                "color": "#EEC900",
                                "text-shadow": "3px 3px 3px blue"
                                //"filter":"shadow(Color=#0000ff,Direction=10,Strength=10)"
                            }
                        }
                    }
                }
            }
        }
        $scope.setDivHeight=function(){
            var w=$('#invationContent').width();
            //$('#invationContent').attr('height',w*1.77);
            var height=w*1.3;
            document.getElementById("invationContent").style.height=height+"px";
            var h=$('#invationContent').height();
            //console.log("run: "+w);
            //console.log("height:"+h);
        }
        $scope.setDivHeight();
    });
